<?php
class My_Images
{
    /**
     * Current image
     * @var array 
     */
    protected $_image;

    public function __construct($image) {
        $this->_image = $image;        
    }

    /**
     * Return image extension (jpg/png/gif)
     * @return string
     */ 
    public function getImageExtension() {
        return pathinfo($this->_image['name'], PATHINFO_EXTENSION);
    }

    /**
     * Check image size
     * @param int $size 
     * @return boolean
     */ 
    public function sizeMoreThan($size) {
        if (intval($this->_image['size']/1024) > $size) {
            return true;
        }
        return false;
    }

    /**
     * Reducing image size
     * @param string $image path to the image
     * @param int $quality image quality
     * @return void
     */ 
    public function compressImage($image, $quality) {
        $imageType = getimagesize($image);                    
        switch ($imageType['mime']) {
            case 'image/jpeg':
                $imageNew = imagecreatefromjpeg($image); 
                break;
            case 'image/png':
                $imageNew = imagecreatefrompng($image);
                break;
            case 'image/gif':
                $imageNew = imagecreatefromgif($image);
                break;                      
        }
        imagejpeg($imageNew, $image, $quality);
    }
}